package testOne2Ten;

import java.util.Stack;

/**
 * 两个栈实现队列
 * Created by Wongy on 2018/3/13.
 */
public class test7 {
    //中转
    private static Stack<Integer> stack1 = new Stack<>();
    //缓存
    private static Stack<Integer> stack2 = new Stack<>();

    private static void push(int num) throws Exception {
        stack1.push(num);
    }

    private static Integer pop() throws Exception {
        if (stack2.isEmpty()) {
            if (stack1.isEmpty()) {
                throw new Exception("栈为空");
            } else {
                while (!stack1.isEmpty()) {
                    stack2.push(stack1.pop());
                }
            }
        }
        return stack2.pop();
    }

    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 10; i++) {
            push(i);
        }
        for (int i = 0; i
                < 10; i++) {
            System.out.println(pop());
        }
    }
}
